interface LogManagerInter extends WechatMiniprogram.RealtimeLogManager {
  debug(...args: any[]): void;
}

const log: LogManagerInter | null = wx.getRealtimeLogManager
  ? (wx.getRealtimeLogManager() as LogManagerInter)
  : null;

export const logManager = {
  debug(...args: any[]) {
    if (!log) return;
    log.debug.apply(log, arguments as any);
  },
  info(...args: any[]) {
    if (!log) return;
    log.info.apply(log, arguments as any);
  },
  warn(...args: any[]) {
    if (!log) return;
    log.warn.apply(log, arguments as any);
  },
  error(...args: any[]) {
    if (!log) return;
    log.error.apply(log, arguments as any);
  },
  setFilterMsg(msg: string) {
    // 从基础库2.7.3开始支持
    if (!log || !log.setFilterMsg) return;
    if (typeof msg !== 'string') return;
    log.setFilterMsg(msg);
  },
  addFilterMsg(msg: string) {
    // 从基础库2.8.1开始支持
    if (!log || !log.addFilterMsg) return;
    if (typeof msg !== 'string') return;
    log.addFilterMsg(msg);
  },
};
